package cn.lf.controller;


import cn.lf.dto.producttype.*;
import cn.lf.service.IProductTypeService;
import cn.lf.utils.ResponseModel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 商品类型 前端控制器
 * </p>
 *
 * @author guoyy
 * @since 2024-04-16
 */
@RestController
@RequestMapping("/product-type")
@Api(tags = "商品类型接口")
public class ProductTypeController {

    @Autowired
    private IProductTypeService productTypeService;


    @GetMapping("/getProductTypePage")
    @ApiOperation("获取产品类型 分页")
    public ResponseModel<IPage<PtPageRepDTO>> getProductTypePage(PtPageReqDTO params){

        IPage<PtPageRepDTO> result = productTypeService.getProductTypePage(params);

        return ResponseModel.buildSuccessResult(result);

    }


    @GetMapping("/getShopProductTypeList")
    @ApiOperation("根据商铺id获取产品类型")
    public ResponseModel<List<ShopPtListDTO>> getShopProductTypeList(@RequestParam String shopId){

        List<ShopPtListDTO> list = productTypeService.getShopProductTypeList(shopId);

        return ResponseModel.buildSuccessResult(list);
    }

    @PostMapping("/saveProductType")
    @ApiOperation("新增或更新商品类型")
    public ResponseModel saveProductType(@RequestBody ProductTypeSaveReqDTO productTypeSaveReqDTO){

        productTypeService.saveProductType(productTypeSaveReqDTO);

        return ResponseModel.buildSuccessResult();
    }

    @GetMapping("/getProductTypeById")
    @ApiOperation("根据id获取产品类型")
    public ResponseModel<ProductTypeSingleDTO> getProductTypeById(@RequestParam String projectTypeId){

        ProductTypeSingleDTO result = productTypeService.getProductTypeById(projectTypeId);

        return ResponseModel.buildSuccessResult(result);

    }

    @GetMapping("/delProductType")
    @ApiOperation("根据id删除产品类型  软删")
    public ResponseModel delProductType(@RequestParam String projectTypeId){

        productTypeService.delProductType(projectTypeId);

        return ResponseModel.buildSuccessResult();
    }

}
